package cn.usian.service.userserviceimpl;

import cn.usian.mapper.UserMapper;
import cn.usian.pojo.User;
import cn.usian.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> findAll(String searchMap) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        if(searchMap !=null && searchMap !=""){
            queryWrapper.like(User::getName,searchMap);
        }
        if(searchMap !=null && searchMap !=""){
            queryWrapper.like(User::getGender,searchMap);
        }
        if(searchMap !=null && searchMap !=""){
            queryWrapper.like(User::getPassword,searchMap);
        }

        return userMapper.selectList(queryWrapper);
    }

    @Override
    public void add(User user) {
        userMapper.insert(user);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void delete(Long id) {
        userMapper.deleteById(id);
    }

    @Override
    public User findById(Long id) {
        return userMapper.selectById(id);
    }
}
